const { sequelize } = require("../db/index")
const { DataTypes, Model } = require("sequelize")

class UserRoomInRelation extends Model {
  static async createRelation({
    roomId,
    userId,
    facultyId,
    majorId,
    sex
  }) {
    try {
      return await UserRoomInRelation.create({
        roomId,
        userId,
        facultyId,
        majorId,
        sex
      })
    } catch (error) {
      console.log(error)
      throw new Error("创建入住关系失败")
    }
  }
}

UserRoomInRelation.init(
  {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true
    },
    roomId: {
      comment: "房间id",
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    userId: {
      comment: "用户id",
      type: DataTypes.INTEGER,
      allowNull: false,
      defaultValue: 0
    },
    facultyId: {
      comment: "学院id",
      type: DataTypes.INTEGER
    },
    majorId: {
      comment: "专业id",
      type: DataTypes.INTEGER
    },
    sex: {
      comment: "性别, 0：男, 1：女",
      type: DataTypes.INTEGER
    }
  },
  {
    sequelize,
    modelName: "userRoomInRelation",
    paranoid: true
  }
)

module.exports = UserRoomInRelation
